﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Celeriq.Common
{
	[DataContract]
	[Serializable]
	[KnownType(typeof(DimensionDefinition))]
	public class FieldDefinition : IFieldDefinition
	{
		public FieldDefinition()
		{
			this.Length = 100;
			this.DataType = RepositoryDefinition.DataTypeConstants.String;
		}

		[DataMember]
		public virtual string Name { get; set; }
		
		[DataMember]
		public virtual RepositoryDefinition.FieldTypeConstants FieldType { get; set; }
		
		[DataMember]
		public virtual int Length { get; set; }
		
		[DataMember]
		public virtual RepositoryDefinition.DataTypeConstants DataType { get; set; }
		
		[DataMember]
		public virtual bool IsPrimaryKey { get; set; }
		
		[DataMember]
		public virtual bool AllowTextSearch { get; set; }

		public bool SortingSupported
		{
			get{return (this.DataType != RepositoryDefinition.DataTypeConstants.GeoCode) && (this.DataType != RepositoryDefinition.DataTypeConstants.List);}
		}

		public bool FilteringSupported
		{
			get { return (this.DataType != RepositoryDefinition.DataTypeConstants.List); }
		}

		public override string ToString()
		{
			return this.Name + ", " + this.DataType.ToString();
		}

	}
}
